package org.example.spring_blog.service;

import org.example.spring_blog.mapper.BlogInfoMapper;
import org.example.spring_blog.mapper.UserInfoMapper;
import org.example.spring_blog.model.BlogInfo;
import org.example.spring_blog.model.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

@Service
public class UserInfoService {
    @Autowired
    UserInfoMapper userInfoMapper;

    @Autowired
    BlogInfoMapper blogInfoMapper;

    public UserInfo getUserInfo(Integer id) {
        return userInfoMapper.selectById(id);
    }

    public UserInfo getByName(String userName) {
        return userInfoMapper.selectByName(userName);
    }

    public UserInfo getAuthorInfo(Integer blogId) {
        BlogInfo blogInfo = blogInfoMapper.selectById(blogId);
        Assert.notNull(blogInfo,"博客id无效");
        return userInfoMapper.selectById(blogInfo.getUserId());
    }
}
